#pragma once
#include <google/protobuf/service.h>
#include "mprpcconfig.h"
#include <muduo/net/TcpServer.h>
#include <muduo/net/EventLoop.h>
#include <muduo/net/InetAddress.h>
#include <muduo/net/Buffer.h>
#include <muduo/base/Timestamp.h>
#include <string>
#include <google/protobuf/descriptor.h>
#include <unordered_map>
class RpcProvider
{
public:
    void NotifyService(google::protobuf::Service* service);

    void run();
private:
    muduo::net::EventLoop loop_;
    struct ServiceInfo
    {
        google::protobuf::Service* service_;
        std::unordered_map<std::string,const google::protobuf::MethodDescriptor*> m_methodMap;

    };
    std::unordered_map<std::string,ServiceInfo> m_serviceInfoMap;
    void onConnection(const muduo::net::TcpConnectionPtr& conn);
    void onMessage(const muduo::net::TcpConnectionPtr& conn,muduo::net::Buffer* buffer
                    , muduo::Timestamp time);
    
    void SendResponse(const muduo::net::TcpConnectionPtr& conn,google::protobuf::Message*);
};